﻿using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using S.EarTag.API.Application.MediatorCommand.MarkCommand;
using S.EarTag.API.Mediator.MediatorCommand.MarkCommand;
using Authorization.Center.Controllers;
using Authorization.Center.SqlServer;

namespace S.EarTag.API.Controllers
{
    /// <summary>
    /// 羊只戴标 -- 归
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    public class MarkController : BaseController
    {
        private readonly IMediator _mediator;
        public MarkController(IMediator mediator,MySqlDbContext _db):base(_db)
        {
            _mediator= mediator;
        }
        /// <summary>
        /// 根据耳号修改使用状态
        /// </summary>
        /// <param name="EarTag"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<IActionResult> UpdMarkEarTagState(string? EarTag)
        {
            MarkUpdMarkStateEarTagCommand command =new MarkUpdMarkStateEarTagCommand();
            command.EarTag = EarTag;
            var result = await _mediator.Send(command);
            return Ok(result);
        }
        /// <summary>
        /// 根据主键Id进行修改使用状态
        /// </summary>
        /// <param name="MarkId"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<IActionResult> UpdMarkIdState(int MarkId)
        {
            MarkUpdMarkIdStateCommand command= new MarkUpdMarkIdStateCommand();
            command.MarkId = MarkId;
            var result=await _mediator.Send(command);
            return Ok(result);
        }
        /// <summary>
        /// 戴标添加
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<IActionResult> AddMark(MarkCreateCommand command)
        {
            command.CreateBy = UserStrategyDto.UserTrueName;
            command.CreateDate= DateTime.Now;
            command.UpdateBy= "";
            command.UpdateDate = "";
            var result=await _mediator.Send(command);
            return Ok(result);
        }
        /// <summary>
        /// 根据Id删除戴标数据
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<IActionResult> DeleteMark(int id)
        {
            MarkDeleteCommand command = new MarkDeleteCommand();
            command.MarkId= id;
            var result=await _mediator.Send(command);
            return Ok(result);
        }
        /// <summary>
        /// 修改戴标信息
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<IActionResult> UpdMark(MarkUpdateCommand command)
        {
            command.UpdateBy = UserStrategyDto.UserTrueName;
            command.UpdateDate = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss");
            var model=await _mediator.Send(command);
            return Ok(model);
        }
        /// <summary> 
        /// 批量删除戴标数据
        /// </summary>
        /// <param name="commnad"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<IActionResult> BathRemoveMark(MarkBatchRemoveCommnad commnad)
        {
            var result=await _mediator.Send(commnad);
            return Ok(result);
        }
        /// <summary>
        /// 添加耳标关系表数据
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<IActionResult> AddEarTagOrMark(EarTagOrMarkCommand command)
        {
            var rest=await _mediator.Send(command);
            return Ok(rest);
        }
        /// <summary>
        /// 根据可视耳号修改状态
        /// </summary>
        /// <param name="EarTag"></param>
        /// <returns></returns>
        [Authorize]
        [HttpPost]
        public async Task<IActionResult> UpdEarTagState(string? EarTag)
        {
            MarkStateEarTagCommand command =new MarkStateEarTagCommand();
            command.EarTag= EarTag;
            var result=await _mediator.Send(command);
            return Ok(result);
        }
    }
}
